package de.luh.slimpp

import com.google.inject.Inject
import de.luh.slimpp.generator.SlimPPGenerator
import de.luh.slimpp.slimPP.ClassType
import de.luh.slimpp.slimPP.NamespaceDefinition
import de.luh.slimpp.slimPP.Visibility
import org.eclipse.xtext.junit4.InjectWith
import org.eclipse.xtext.junit4.XtextRunner
import org.junit.Test
import org.junit.runner.RunWith

import static org.junit.Assert.*

@RunWith(typeof(XtextRunner))
@InjectWith(typeof(SlimPPInjectorProvider))
class SlimPPParserTest extends RuleParserHelper {

	@Inject SlimPPGenerator g

	@Test
	def void testParseVisibility() {
		var visibility = '+'.parseRule(typeof(Visibility)) as Visibility
		assertTrue(visibility.public)
		assertFalse(visibility.protected)
		assertFalse(visibility.private)

		visibility = '#'.parseRule(typeof(Visibility)) as Visibility
		assertFalse(visibility.public)
		assertTrue(visibility.protected)
		assertFalse(visibility.private)

		visibility = '-'.parseRule(typeof(Visibility)) as Visibility
		assertFalse(visibility.public)
		assertFalse(visibility.protected)
		assertTrue(visibility.private)
	}

	@Test
	def void testParseNamespaceDefinition() {
		var ns = "'comment' namespace a.b.c {}".parseRule(typeof(NamespaceDefinition)) as NamespaceDefinition
		assertEquals('a::b::c', g.compile(ns.name))
		assertTrue(ns.definitions.empty)

		ns = "a.b.c {}".parseRule(typeof(NamespaceDefinition)) as NamespaceDefinition
		assertEquals('a::b::c', g.compile(ns.name))
		assertTrue(ns.definitions.empty)
	}

	@Test
	def void testParseClassType() {
		var type = 'interface'.parseRule(typeof(ClassType)) as ClassType
		assertTrue(type.interface)
		assertFalse(type.abstract)
		assertFalse(type.isClass)

		type = 'abstract'.parseRule(typeof(ClassType)) as ClassType
		assertFalse(type.interface)
		assertTrue(type.abstract)
		assertFalse(type.isClass)

		type = 'class'.parseRule(typeof(ClassType)) as ClassType
		assertFalse(type.interface)
		assertFalse(type.abstract)
		assertTrue(type.isClass)
	}
}
